package com.example.demo.entity.response.user;

import com.example.demo.common.entity.response.BaseResponse;
import com.example.demo.entity.pojo.user.UserPoJo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * .
 *
 * @author Mei Ruoxiao
 * @since 2020/8/31
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ApiModel("用户信息响应")
public class UserResponse extends BaseResponse {

    @ApiModelProperty(value = "名称", required = true, example = "张三")
    private String name;

    @ApiModelProperty(value = "密码", required = true, example = "zs98754")
    private String password;

    public static UserResponse of(final UserPoJo poJo) {
        UserResponse response = new UserResponse();
        if (Objects.isNull(poJo)) {
            return response;
        }
        // 将 Domain 对象转换成 Response 对象
        BeanUtils.copyProperties(poJo, response);
        return response;
    }
}
